package Async

import (
	"ali-hr/Database"
	"context"
	"fmt"
	"github.com/gookit/goutil/dump"
	"github.com/hibiken/asynq"
)

/**
 * Created by Goland
 * User: wkk alisleepy@hotmail.com
 * Time: 2022/4/30 - 15:24
 * Desc: <消费者>
 */

// HandleTask 执行具体任务
func HandleTask() error {
	redis := Database.Redis
	srv := asynq.NewServer(
		redis,
		asynq.Config{Concurrency: 10},
	)

	err := srv.Run(asynq.HandlerFunc(handler))
	return err
}

func handler(ctx context.Context, t *asynq.Task) error {
	switch t.Type() {
	case "export_department":
		dump.P("导出部门操作")
	case "export_staff":
		dump.P("导出员工操作")
	default:
		return fmt.Errorf("unexpected task type: %s", t.Type())
	}

	return nil
}
